﻿using Acr.UserDialogs;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace myfirstmaui.ViewModels
{
    public class MyPage22ViewModel : ObservableValidator    
    {
        private int? age;

        [Required(ErrorMessage = "不能为空!")]
        [Range(18,120,ErrorMessage = "必须是18和120之间")]
        public int? Age
        {
            get { return age; }
            //第3个参数是必须校验的..
            set { SetProperty(ref age, value,true); }
        }

        private bool active1;
        public bool Active1
        {
            get { return active1; }
            set
            {                
                SetProperty(ref active1, value);
                ImageSource1 = Active1 ? "dotnet_bot.png" : "dotnet_bot2.png";
            } //第2句无意义，可是必须又要除服..
        }

        private string imageSource1;
        public string ImageSource1 {get { return imageSource1;} set { SetProperty(ref imageSource1, value);}}

        private string myShowText;
        public string MyShowText { get { return myShowText; } set { SetProperty(ref myShowText, value); } }

        public ICommand BtnCommandSendHand { get; set; } //

        string? errorMessages;
        public string? ErrorMessages
        {
            get { return errorMessages; }            
            set { SetProperty(ref errorMessages, value); }
        }

        public MyPage22ViewModel()
        {
            BtnCommandSendHand = new RelayCommand<object>(DoBtnCommandSendHand);
        }


        private void DoBtnCommandSendHand(object button)
        {
            var timeoutCancellationTokenSource = new CancellationTokenSource();
            var t = Task.Run(async () =>
            {                
                string text = "欢-迎-来-到-神-秘-魔-法-小-屋-,-解-开-你-的-困-惑-,-从-对-塔-罗-算-命-开-始-,-希-望-你-的-命-运-能-从-此-改-变" +
                "-这-个-游-戏-很-简-单,-就-是-随-机-抽-三-张-牌-(-开-始-选-三-张-牌-)-" +
                "适-合-用-来--解-决-一-些-没-有-特-定-答-案-的-问-题-,-比-如-他-(-她-)-现-在-事-业-怎-么-样-爱-情-怎-么-样-生-命-怎-么-样" +
                "-或-者-他-(-她-)-喜-欢-我-吗-?-和-他-(-她-)-会-长-久-吗-?-(-开-始-选-问-题-)-" +
                "-我-的-任-务-就-是-给-你-解-读-你-或-者-你-们-的-命-运-!-(-解-答-问-题-)-";
                char separator = '-';
                string[] parts = text.Split(separator);

                foreach (var part in parts)
                {
                    await Task.Delay(500);
                    MyShowText += part;
                    
                }
            }, timeoutCancellationTokenSource.Token);
            return;
        }
    }
}
